<template>
	<view>
		<u-navbar class="navbar" :border-bottom="false" title="上传凭证" :title-size="36" :title-bold="true" :title-color="textColor">
			
		</u-navbar>
		<view class="container">
			<!--  -->
			<view class="u-m-t-60">
				<image src="/static/order/yanzheng_small.png" style="width: 30rpx;height: 30rpx;vertical-align:middle;" mode=""></image>
				<text class="u-font-26 badge-color u-m-l-10" style="vertical-align:middle;">请上传付款凭证（最多6张）</text>
			</view>
			<view class="u-m-t-30">
				<u-upload :action="baseUrl + 'api/Resource/UploadToOss'"
					:file-list="fileList"
					:header="headerToken" 
					 max-count="6"
					 :source-type="['album']"
					 @on-success="onSuccess"
					 @on-remove="onRemove"
					 ></u-upload>
			</view>
		</view>
		<!-- 按钮 -->
		<view class="bottom-button">
			<!-- <u-button hover-class="none" shape="circle" :ripple="true" :hair-line="false" :custom-style="getBtStyle('plain',-1, 90)" style="width: 100%;" @click="showPay">其他方式付款</u-button> -->
			<u-button  hover-class="none" shape="circle" :hair-line="false" :custom-style="getBtStyle('default', -1, 90)" style="width: 100%;margin-left: 20rpx;" @click="toOrder">完成支付</u-button>
			
		</view>
	</view>
</template>

<script>
	// import Dropdown from '@/components/dt-dropdown/dt-dropdown.vue'
	import AkDropdown from '@/components/ak-dropdown/index.vue'
	import indexConfig from '@/config/index.config';
	import { useUserStore } from '@/store/user.js';
	import { mapState } from 'pinia';
	export default {
		components: { AkDropdown },
		data() {
			return {
				id: null,
				action:indexConfig.baseUrl+'/api/Resource/Upload',
				fileList:[],
				payTypeShow: false,
				type: 4,
				resourceList:[],
			}
		},
		onLoad(options) {
			this.id = options.id;
		},
		computed:{
			...mapState(useUserStore, {
				headerToken(store){
				return {
					Authorization: 'Bearer ' + store.user.access_token,
				}
			}})
		},
		methods: {
			back(){
			uni.navigateBack();	
			},
			onSuccess(data) {
				uni.hideLoading()
				this.resourceList.push(data.data[0].id);
			},
			onRemove(data) {
				this.resourceList.splice(data,1)
			},
			async toOrder() {
				uni.showLoading({
					title:'loading..'
				})
				if(this.resourceList.length===0){
					uni.hideLoading({
						title:'loading..'
					});
					this.$u.toast('支付凭证不得为空');
					return false;
				}
				
				let res = await this.$newHttp.post('api/TradePayment/ConfirmedReceiptOfPayment', {
					id: this.id,
					resourceIds:this.resourceList
				});
				uni.hideLoading({
					title:'loading..'
				})
				if(res.code === 200){
					uni.$emit('refreshData')
					uni.navigateBack({
						delta: 1
					});
				}else{
					this.$u.toast('收款失败，错误信息：'+res.erroMessage);
				}
			}
		}
	}
</script>

<style>
	page {
		background-color: #FFFFFF;
	}
</style>
<style lang="scss" scoped>
	.container {
		padding: 30rpx 35rpx;
	}
	.bottom-button {
		padding: 0 35rpx;
		position: fixed;
		width:100%;
		bottom: 100rpx;
		// margin: 0;
		display: flex;
		// justify-content: space-between;
	}
</style>
